<?php

declare(strict_types=1);
/**
 * Created by project.
 * User: huanzipap
 * Date: 2023/5/10
 * Time: 11:25
 */
namespace App\Libs;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\ResponseInterface;

//use Hyperf\HttpServer\Contract\ResponseInterface as HttpResponse;

class ReMsg
{
//    protected HttpResponse $response;
//
//    public function __construct(HttpResponse $response)
//    {
//        $this->response = $response;
//    }
    #[Inject]
    protected ResponseInterface $response;

    /**
     * @param $code
     * @param $message
     * @param $data
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function re($code, $message = null, $data = null): \Psr\Http\Message\ResponseInterface
    {
        if ($message == null) {
            $message = CodeToMessage::code2msg($code);
        }
        return $this->response->json(
            [
                'code' => $code,
                'message' => $message,
                'data' => $data
            ]
        );
    }

}